import React from 'react';
import { View, Button, StyleSheet } from 'react-native';
import { pickFile, readFile } from '../utils/fileUtils';
import { useNavigation } from '@react-navigation/native';

export const HomeScreen = () => {
  const navigation = useNavigation();

  const handlePickFile = async () => {
    const file = await pickFile();
    if (file) {
      const content = await readFile(file.uri);
      if (content) {
        navigation.navigate('Reader', { content });
      }
    }
  };

  return (
    <View style={styles.container}>
      <Button title="打开TXT文件" onPress={handlePickFile} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});
